package cn.edu.ujn.booksshop.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.ujn.booksshop.dao.User;
import cn.edu.ujn.booksshop.dao.UserMapper;
import cn.edu.ujn.util.Page;

@Service
@Transactional
public class UserServiceImpl implements IUserService {

	@Autowired
	private UserMapper userDao;

	@Autowired
	public IUserService userService;

	// 通过id查找用户
	@Override
	public User selectByPrimaryKey(Integer id) {
		User key = this.userDao.selectByPrimaryKey(id);
		return key;
	}
	
	@Override
	public User findUser(User user) {
		user = this.userDao.findUser(user);
		return user;
	}

	// userMangment.jsp查找所有user
	@Override
	public Page<User> selectAll(Integer page, Integer rows) {
		List<User> list = this.userDao.selectAll((page - 1) * rows, rows);
		Page<User> pages = new Page<User>();
		pages.setPage(page);
		pages.setRows(list);
		pages.setSize(rows);
		Integer count = userDao.selectCount();
		pages.setTotal(count);
		return pages;
	}

	@Override
	public Integer selectCount() {
		Integer selectCount = this.userDao.selectCount();
		return selectCount;
	}

	@Override
	public int insertSelective(User user) {
		int insert = this.userDao.insertSelective(user);
		return insert;

	}

	@Override
	public int deleteByPrimaryKey(Integer userid) {
		int deleteByPrimaryKey = this.userDao.deleteByPrimaryKey(userid);
		return deleteByPrimaryKey;
	}

	@Override
	public int updateByPrimaryKeySelective(User row) {
		int updateByPrimaryKeySelective = this.userDao.updateByPrimaryKeySelective(row);
		return updateByPrimaryKeySelective;
	}
}
